<%-- 
    Document   : search_services
    Created on : Dec 6, 2010, 2:44:18 PM
    Author     : M Bilal
--%>

<%@ page import="java.io.*,java.util.*,java.sql.*,java.net.*"%>
<%@ page import="wap.rockvilletech.portal.DBProc"%>
<%
            DBProc dbproc = DBProc.getInstance();
            String strSearchText = (request.getParameter("txtsrh") != null && !request.getParameter("txtsrh").isEmpty()) ? request.getParameter("txtsrh").toString() : "";

            //Pagging
            int intBlockLength = 5, intRecordsToBeDisplayed = 0, intRecordsToBeFetched = 0, intCountTotal = 0, intPageID = 0, intLastPage = 0;
            String strPagingLinks = "", pid = "";
            boolean computePaging = false, isNext = true;
            pid = request.getParameter("pid") != null ? request.getParameter("pid").toString() : "0";
            Vector vServices = dbproc.getServicesSearch(pid, strSearchText);
            if (vServices != null) {
                intCountTotal = (Integer) vServices.get(0);
                intRecordsToBeDisplayed = intRecordsToBeFetched = (Integer) (vServices.get(1));
                try {
                    intLastPage = intCountTotal / intRecordsToBeDisplayed;
                    intPageID = Integer.parseInt(pid.toString());
                    if (intPageID > intLastPage) {
                        intPageID = intLastPage;
                    }
                    if (intCountTotal == (int) (intRecordsToBeDisplayed * (intPageID + 1))) {
                        intLastPage--;
                    }
                } catch (NumberFormatException ex) {
                }

                if (vServices.size() - 1 < intRecordsToBeFetched) {
                    intRecordsToBeDisplayed -= (intRecordsToBeFetched - vServices.size());
                    intRecordsToBeFetched = vServices.size();
                    isNext = false;
                }

                computePaging = intCountTotal > intRecordsToBeDisplayed;
                if (computePaging) {
                    // Call the method which will generate Page links

                    wap.rockvilletech.util.Paging.computePaging(request, "search.jsp?",
                            intRecordsToBeFetched, intRecordsToBeDisplayed,
                            intCountTotal, intBlockLength, intLastPage, intPageID,
                            isNext);
                    strPagingLinks = wap.rockvilletech.util.Paging.getPagingLinks();
                }
            }//end vector if
%>
<div>
    <table cellpadding="0" cellspacing="0" width="100%">
        <tr><td align="left" style="padding:5px 0px 0px 10px;">
                <table bgcolor="#d5d5d5" border="0" cellpadding="0" cellspacing="0">
                    <tr>
                        <td><img src="<%=request.getContextPath()%>/images/bar_left.png" alt="" /></td>
                        <td><b>&nbsp;Services Search&nbsp;</b></td>
                        <td><img src="<%=request.getContextPath()%>/images/bar_right.png" alt="" /></td>
                    </tr>
                </table>
            </td></tr>
        <tr><td align="left" style="background-image:url('images/new/catagory_top_part.jpg');background-repeat: repeat-x; padding:6px 0px 0px 0px; ">

                <%
                            try {
                                String ititle = "";
                                String strServiceId = "";
                                String[] arrNews = null;
                                if (vServices.size() == 2) {
                                    strPagingLinks = "No Data Available!";
                                }
                                for (int idx = 2; idx < vServices.size(); idx++) {
                                    arrNews = (String[]) vServices.get(idx);
                                    strServiceId = arrNews[0];
                                    ititle = arrNews[1];
                                    /* ititle = wap.rockvilletech.util.StringUtils.toUnicode(ititle);
                                    try{
                                    ititle=java.net.URLDecoder.decode(ititle,"UTF-8");
                                    }catch(Exception exDecode){}
                                     */

                %>
                <div>&nbsp; - <a class="LinkIndex" href="<%=request.getContextPath()%>/ContentService.jsp?srvid=<%=strServiceId%>"><%=ititle%></a></div>
                <%
                                }

                                out.println(strPagingLinks);


                            } catch (Exception exRssNewsSearch) {
                            }
                %>
            </td>
        </tr>
    </table>
</div>
<br/>

<%-- End --%>